<div class="form">
    <?php echo validation_errors(); ?>
    
    <?php echo form_open($action); ?>

        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">个人资料</a></li>
                <li><a href="#tabs-2">修改密码</a></li>
            </ul>
        <div id="tabs-1">
            <table class="form">
                <tr>
                    <th class="span-3">用户名</th>
                    <td><?php echo $user['u_name']; ?></td>
                </tr>
                <tr>
                    <th>有效期</th>
                    <td><?php echo $user['u_first_date'] . ' 至 ' . $user['u_last_date']; ?></td>
                </tr>
                <tr>
                    <th>姓名</th>
                    <td><?php echo $user['u_real_name']; ?></td>
                </tr>
                <tr>
                    <th>性别</th>
                    <td><?php echo $user['u_sex']; ?></td>
                </tr>
                <tr>
                    <th>联系电话</th>
                    <td><?php echo $user['u_telephone']; ?></td>
                </tr>
                <tr>
                    <th>员工组权限</th>
                    <td>
                        <?php 
                        $today = date('Y-m-d');
                        foreach ($user_roles as $ur) {
                            $text = $ur['ur_first_date'] . ' 至 ' . $ur['ur_last_date'] . ' [ ' . $roles[$ur['ur_rid']] . ' ]<br>';
                            if ($today >= $ur['ur_first_date'] && $today <= $ur['ur_last_date']) {
                                echo '<span>'.$text.'</span>';
                            } else {
                                echo '<span class="inactive">'.$text.'</span>';
                            }
                        } 
                        ?>
                    </td>
                </tr>
            </table>
        </div>
        <div id="tabs-2">
            <div>
                <label class="span-3">原密码<span class="required">*</span></label>
                <input class="text span-4" type="password" name="old_password" />
                <div class="clear"></div>
            </div>
            <div>
                <label class="span-3">新密码<span class="required">*</span></label>
                <input class="text span-4" type="password" name="u_password" />
                <div class="info span-10">请输入至少6位，建议由数字，大小写字母和特殊字符组成</div>
                <div class="clear"></div>
            </div>
            <div>
                <label class="span-3">再输一次<span class="required">*</span></label>
                <input class="text span-4" type="password" name="u_password_again" />
                <div class="clear"></div>
            </div>
            <div class="form-actions">
                <input type="submit" class="form-submit" value="保存" />
            </div>
        </div>
    </form>
</div>
<script>
    $(function() {
        $("#tabs").tabs();

        $(".normal-date").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: "yy-mm-dd",
        });
        
        /**
         * 角色复选框 点击事件
         */
        $("#tabs-3 input[type=checkbox]").click(function(){
            var divObj = $(this).parent().parent();
            if (this.checked) {
                divObj.children("input[name^=ur_first_date]").val('<?php echo date('Y-m-d'); ?>');
                divObj.children("input[name^=ur_last_date]").val('<?php echo (date('Y') + 10) . '-12-31'; ?>');
            } else {
                divObj.children("input[name^=ur_first_date]").val('');
                divObj.children("input[name^=ur_last_date]").val('');
            }
        });
        
        <?php if (strpos($action, 'update')): ?>
        
        /**
         * 重新设置密码 点击事件
         */
        $("#reset_password").click(function(){
            if (this.checked) {
                $("#password-div").show();
            } else {
                $("#password-div").hide();
            }
        });
        
        /**
         * 设置属性，触发点击事件
         */
        if ($("#reset_password").prop("checked")) {
            $("#password-div").show();
        } else {
            $("#password-div").hide();
        }
        <?php endif; ?>
    });
</script>